<?php

namespace app\service\Web;

use app\model\Message;
use Exception;
use app\util\GlobalCode;
use app\util\GlobalMsg;

class MessageService
{

    public static function add(array $where = [])
    {
        $message = new Message();
        if (!empty($where['id'])) {
            throw new Exception(GlobalMsg::ADD_ID);
        }
        isset($where['content']) && $message->content = $where['content'];
        isset($where['email']) && $message->email = $where['email'];
        isset($where['ip']) && $message->ip = $where['ip'];
        isset($where['is_sent']) && $message->is_sent = $where['is_sent'];
        isset($where['mobile']) && $message->mobile = $where['mobile'];
        isset($where['pics']) && $message->pics = $where['pics'];
        isset($where['real_name']) && $message->real_name = $where['real_name'];
        isset($where['remark']) && $message->remark = $where['remark'];
        isset($where['status']) && $message->status = $where['status'];
        isset($where['title']) && $message->title = $where['title'];
        isset($where['type']) && $message->type = $where['type'];
        isset($where['company_name']) && $message->company_name = $where['company_name'];
        isset($where['website']) && $message->website = $where['website'];
        isset($where['city']) && $message->city = $where['city'];

        $res = $message->save();
        if ($res == false) {
            throw new Exception(GlobalMsg::SAVE_FAIL);
        }
        return $res;
    }
}
